package com.ruoyi.crm.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.crm.domain.CustomerProduct;
import com.ruoyi.crm.service.ICustomerProductService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 顾客产品信息Controller
 *
 * @author ruoyi
 * @date 2021-08-27
 */
@RestController
@RequestMapping("/customerProduct")
public class CustomerProductController extends BaseController
{
    @Autowired
    private ICustomerProductService customerProductService;

    /**
     * 查询顾客产品信息列表
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:list")
    @GetMapping("/list")
    public TableDataInfo list(CustomerProduct customerProduct)
    {
        startPage();
        List<CustomerProduct> list = customerProductService.selectCustomerProductList(customerProduct);
        return getDataTable(list);
    }

    /**
     * 导出顾客产品信息列表
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:export")
    @Log(title = "顾客产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerProduct customerProduct) throws IOException
    {
        List<CustomerProduct> list = customerProductService.selectCustomerProductList(customerProduct);
        ExcelUtil<CustomerProduct> util = new ExcelUtil<CustomerProduct>(CustomerProduct.class);
        util.exportExcel(response, list, "顾客产品信息数据");
    }

    /**
     * 获取顾客产品信息详细信息
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:query")
    @GetMapping(value = "/{cpId}")
    public AjaxResult getInfo(@PathVariable("cpId") String cpId)
    {
        return AjaxResult.success(customerProductService.selectCustomerProductByCpId(cpId));
    }

    /**
     * 新增顾客产品信息
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:add")
    @Log(title = "顾客产品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerProduct customerProduct)
    {
        return toAjax(customerProductService.insertCustomerProduct(customerProduct));
    }

    /**
     * 修改顾客产品信息
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:edit")
    @Log(title = "顾客产品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerProduct customerProduct)
    {
        return toAjax(customerProductService.updateCustomerProduct(customerProduct));
    }

    /**
     * 删除顾客产品信息
     */
    @PreAuthorize(hasPermi = "crm:customerProduct:remove")
    @Log(title = "顾客产品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cpIds}")
    public AjaxResult remove(@PathVariable String[] cpIds)
    {
        return toAjax(customerProductService.deleteCustomerProductByCpIds(cpIds));
    }
}